package com.lxh.student.web.controller;


import com.lxh.student.common.Const;
import com.lxh.student.common.ResponseResult;
import com.lxh.student.entity.RcStudent;
import com.lxh.student.service.RcStudentService;
import com.lxh.student.util.DateUtil;
import com.lxh.student.vo.input.SearchChoseCourseVo;
import com.lxh.student.vo.output.LoginInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author LXh
 * @since 2022-10-24
 */
@RestController
@RequestMapping("/rc-student")
public class RcStudentController {
    @Autowired
    private RcStudentService studentService;

    @RequestMapping("/searchCourse")
    public ResponseResult searchCourse(SearchChoseCourseVo courseVo, HttpSession session){
        LoginInfoVo info = (LoginInfoVo) session.getAttribute(Const.IS_LOGIN);
        //封装登入学员的id进行查询的数据对象SearchChoseCourseVo input vo
        courseVo.setStudentId(info.getUserId());
        return studentService.searchCourse(courseVo);

    }

    //获取登录学生的信息
    @GetMapping("/getStudentInfo")
    public ResponseResult getStudentInfo(HttpSession session){
        //获取用户登录信息
        LoginInfoVo infoVo = (LoginInfoVo) session.getAttribute(Const.IS_LOGIN);
        //访问业务层获取用户信息数据
        return studentService.getStudentInfo(infoVo.getUserId());
    }

    //更新学生信息
    @PostMapping("/updateStudent")
    public ResponseResult updateStudent(HttpSession session,String studentEmail,String studentBirthday,String studentPassword){
        LoginInfoVo info = (LoginInfoVo) session.getAttribute(Const.IS_LOGIN);
        RcStudent stu = new RcStudent(info.getUserId(),studentPassword,studentEmail, DateUtil.stringToDate(studentBirthday));
        return studentService.updateStudent(stu);
    }

}
